package pos.domain;

import java.util.List;

import pos.data.JDBCSubTypeDAO;

public class SubTypeStore {

	@SuppressWarnings("unused")
	private List<SubType> subTypes;
	private static SubTypeStore subTypeStore;

	public static synchronized SubTypeStore getInstance() {
		subTypeStore = new SubTypeStore();

		return subTypeStore;
	}

	public SubTypeStore() {
		subTypes = new JDBCSubTypeDAO().getAllSubTypes();
	}

	public List<SubType> getSubTypes() {
		// return subTypes;
		return (new JDBCSubTypeDAO()).getAllSubTypes();
	}

	public SubType getSubTypeById(String idSubType) {
		return (new JDBCSubTypeDAO()).getSubTypeById(idSubType);
	}
	
	public SubType getSubTypeByName(String name) {
		return (new JDBCSubTypeDAO()).getSubTypeByName(name);
	}

	public List<SubType> getListSubTypesByEntity(Entity entity) {
		return (new JDBCSubTypeDAO()).getListSubTypesByEntity(entity.getId());
	}
	public List<SubType> getListSubTypesByEntityAndType(Entity entity, Type type) {
		return (new JDBCSubTypeDAO()).getListSubTypesByEntityAndType(entity.getId(),type.getId());
	}

	public SubType insertSubType(SubType subType, Type type, Entity entity) {
		return new JDBCSubTypeDAO().insertSubType(subType, type.getId(), entity.getId());
	
	}

	public void removeSubType(SubType subType) {
		// didn't remove the associations because the objective is to have data
		new JDBCSubTypeDAO().removeSubType(subType);
	}
	
	public boolean existSubType(SubType subType, Type type, Entity entity){
		return new JDBCSubTypeDAO().existSubType(subType.getName(), type.getId(), entity.getId());
	}
}
